from core.support import set_cutscene, get_game
from core.item import Item
from core.action import Action
from core.game import Game
from rooms.councilroom import CouncilRoom

class Josiah(Item):
    def __init__(self):
        Item.__init__(self, "josiah")    # do basic initialization for every item
        
        # build list of actions
        # are we going to do a swipe action?  or just check if the card is in inventory?
        # if we just check, then we don't need this action at all
        self.add_action(UseJosiah)
    
    def get_description(self):
        return "Josiah"
# added using concept from OILCAN.PY
class UseJosiah(Action):
    def __init__(self):
        Action.__init__(self, "use_josiah")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Use Josiah"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    # only show button if Neil is in inventory
    
    def is_enabled(self):
        game = get_game()
        player = game.get_player()
        # only shows up in council room
        if game.history[-1].get_id() == 'councilroom':
            # check if council room is unlocked
            if game.get_room('councilroom', CouncilRoom).locked == True:
                # only works if you have Neil in inventory    
                if ('josiah' in player.inventory):
                    return True
        else:
            return False
        
# only works in council room . 
    def do_action(self,game,room,request):
        if game.history[-1].get_id() == 'councilroom':
            if room.locked:
                room.locked = False
                room.solving = True
            else:           
                    set_cutscene("The Council Room is locked.  Find someone who has the keys")
        else:
            set_cutscene("What do you want to use Josiah for?")

        return